<template>
  <div class="search-result">
    <!-- <div class="emptyBox" v-if="!searchResult.length">
      <img src="~@/assets/images/empty/img_Empty-page.png">
      <div class="decorate">当前暂无内容~</div>
      <div class="toHome" @click="()=>$router.replace('/home')">去逛逛</div>
    </div> -->
    <van-list
      v-model="loading"
      :finished="!needLoading"
      finished-text="没有更多了"
      @load="load"
    >
      <list-view ref="listView" @itemClick="itemClick" :listData="searchResult"></list-view>
    </van-list>
    <!-- <mu-container ref="container" class="loadmore-content" >
      <mu-load-more @refresh="refresh" :refreshing="refreshing" :loading="loading" @load="load">
        <list-view ref="listView" @itemClick="itemClick" :listData="searchResult"></list-view>
      </mu-load-more>
    </mu-container> -->
  </div>
</template>

<script>
import ListView from '@/components/listview/listview'
import { summaryMixin } from '@/base/mixins/tableMix'
import { mineApi } from '@/api'
export default {
  name: 'search-result',
  components: {
    ListView
  },
  mixins: [summaryMixin],
  async created() {
  },
  data() {
    return {
      num: 10,
      text: 'List',
      searchResult: [],
      fromType: ''
    }
  },
  methods: {
    onQueryChange() {
      // this.$vux.toast.show({
      //   text: 'Loading'
      // })
      this.$toast('hello')
      // Toast.message('hello world')
    },
    updatedData(data, type, query) {
      this.searchResult = data
      this.fromType = type
      this.query = query
    },
    async  _getDataList(data) {
      console.log('data', this.limit, this.page)
      const res = await mineApi.getCategory({
        search: this.query,
        pageSize: this.limit,
        pageNo: this.page
      })
      if (!res.data) {
        res.data = []
        return []
      }
      this.searchResult = this.searchResult.concat(res.data.records)
      this.needLoading = !(this.limit > this.searchResult.length)
      console.log('this.needLoading', this.needLoading)
      return res.data
    },
    itemClick(item, index) {
      window.__sensors__.track('clickSearchResult', {
        key_word: this.query,
        is_history: this.fromType === 'history',
        is_hot_search: this.fromType === 'hot',
        click_series_number: index,
        commodity_name: item.title,
        commodity_id: item.goods_id
      })
    },
    refresh() {
      console.log('refresh')
      this.refreshing = true
      if (this.$refs.container) {
        this.$refs.container.scrollTop = 0
      }
      setTimeout(() => {
        this.refreshing = false
        this.text = this.text === 'List' ? 'Menu' : 'List'
        this.num = 10
      }, 2000)
    }
  },

  computed: {
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/assets/css/mixin.scss";
@import 'src/assets/css/variables.scss';
.search-result{
  background-color: #fff;
  padding: 10px;
  .noResult{
    text-align: center;
    color: $color-tips;
    img{
      width: 60%;
      left: 20%;
      position: relative;
    }
  }
}
</style>
